/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.team1662.commands;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.team1662.RobotMap;

/**
 *
 * @author programmer
 */
public class Drive extends CommandBase {
    private DigitalInput limitSwitch = new DigitalInput(2);
    //The light sensor sends True because it's reflected. 
    //I need to programme for it to detect when the signal is false
    //then add a reset variable.
    private DigitalInput limitSwitchLow = new DigitalInput(3);

    
    public Drive() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        drivetrain.tankDrive(0, 0);
        drivetrain.cheezit(0);
        drivetrain.pickup(0);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute(){
        drivetrain.tankDrive(-oi.getRightStick(), -oi.getLeftStick());
        //SmartDashboard.putNumber("LeftStick value:", oi.getLeftStick());
        //SmartDashboard.putNumber("RightStick value", oi.getRightStick());
        if(oi.getLowButton() == true)
            drivetrain.cheezit(-1);
        else
            drivetrain.cheezit(0);
        /*
        if(oi.getLowButton() == true){
            if(limitSwitchLow.get() == true)
                drivetrain.cheezit(RobotMap.mtrSpeed);
            else
                drivetrain.cheezit(0);
        }
        else if(oi.getMid1Button() == true){
            if(limitSwitch.get() == true)
                drivetrain.cheezit(RobotMap.mtrSpeed);
            else
                drivetrain.cheezit(0);
        }
        else
            drivetrain.cheezit(0);
        
        */
        
        
        /*
        if(limitSwitch.get() != true || limitSwitchLow.get() != true)
            drivetrain.cheezit(0);
        else {
            if(oi.getLowButton() == true){
                drivetrain.cheezit(RobotMap.mtrSpeed);
            }
            else if(oi.getMid1Button() == true)
                drivetrain.cheezit(RobotMap.mtrSpeed);
            else
                drivetrain.cheezit(0);
        }
        */
        drivetrain.pickup(oi.getConveyorThrottle());
        
        //DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+oi.getSomething());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser1, 1, ""+oi.getLeftStick());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser2, 1, ""+drivetrain.getChMotor());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, ""+limitSwitch.get());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, ""+limitSwitchLow.get());
        DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser5, 1, ""+oi.getLowButton());
        DriverStationLCD.getInstance().updateLCD();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
        drivetrain.tankDrive(0, 0);
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        drivetrain.tankDrive(0, 0);
        drivetrain.cheezit(0);
        drivetrain.pickup(0);
    }
}